home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Games / MAME / src / drivers / shanghai.c < prev    next >
C/C++ Source or Header  |  2000-04-23  |  19KB  |  778 lines

  1. /***************************************************************************
  2.  
  3. Shanghai
  4.  
  5. driver by Nicola Salmoria
  6.  
  7. this is mostly working, but the HD63484 emulation is incomplete. The continue
  8. yes/no display is wrong, I think this is caused by missing "window" emulation.
  9.  
  10. Also, the game locks up after you win a round.
  11.  
  12. ***************************************************************************/
  13.  
  14. #include "driver.h"
  15.  
  16. /* the on-chip FIFO is 16 bytes long, but we use a larger one to simplify */
  17. /* decoding of long commands. Commands can be up to 64KB long... but Shanghai */
  18. /* doesn't reach that length. */
  19. #define FIFO_LENGTH 50
  20. static int fifo_counter;
  21. static UINT16 fifo[FIFO_LENGTH];
  22. static UINT8 *HD63484_ram;
  23. static UINT16 HD63484_reg[256/2];
  24. static int org,rwp;
  25. static UINT16 cl0,cl1,ccmp;
  26. static INT16 cpx,cpy;
  27.  
  28.  
  29. static int instruction_length[64] =
  30. {
  31.      0, 3, 2, 1,    /* 0x */
  32.      0, 0,-1, 2,    /* 1x */
  33.      0, 3, 3, 3,    /* 2x */
  34.      0, 0, 0, 0,    /* 3x */
  35.      0, 1, 2, 2,    /* 4x */
  36.      0, 0, 4, 4,    /* 5x */
  37.      5, 5, 5, 5,    /* 6x */
  38.      5, 5, 5, 5,    /* 7x */
  39.      3, 3, 3, 3,     /* 8x */
  40.      3, 3,-2,-2,    /* 9x */
  41.     -2,-2, 2, 4,    /* Ax */
  42.      5, 5, 7, 7,    /* Bx */
  43.      3, 3, 1, 1,    /* Cx */
  44.      2, 2, 2, 2,    /* Dx */
  45.      5, 5, 5, 5,    /* Ex */
  46.      5, 5, 5, 5     /* Fx */
  47. };
  48.  
  49. static char *instruction_name[64] =
  50. {
  51.     "undef","ORG  ","WPR  ","RPR  ",    /* 0x */
  52.     "undef","undef","WPTN ","RPTN ",    /* 1x */
  53.     "undef","DRD  ","DWT  ","DMOD ",    /* 2x */
  54.     "undef","undef","undef","undef",    /* 3x */
  55.     "undef","RD   ","WT   ","MOD  ",    /* 4x */
  56.     "undef","undef","CLR  ","SCLR ",    /* 5x */
  57.     "CPY  ","CPY  ","CPY  ","CPY  ",    /* 6x */
  58.     "SCPY ","SCPY ","SCPY ","SCPY ",    /* 7x */
  59.     "AMOVE","RMOVE","ALINE","RLINE",     /* 8x */
  60.     "ARCT ","RRCT ","APLL ","RPLL ",    /* 9x */
  61.     "APLG ","RPLG ","CRCL ","ELPS ",    /* Ax */
  62.     "AARC ","RARC ","AEARC","REARC",    /* Bx */
  63.     "AFRCT","RFRCT","PAINT","DOT  ",    /* Cx */
  64.     "PTN  ","PTN  ","PTN  ","PTN  ",    /* Dx */
  65.     "AGCPY","AGCPY","AGCPY","AGCPY",    /* Ex */
  66.     "RGCPY","RGCPY","RGCPY","RGCPY"     /* Fx */
  67. };
  68.  
  69. int HD63484_start(void)
  70. {
  71.     fifo_counter = 0;
  72.     HD63484_ram = malloc(0x200000);
  73.     if (!HD63484_ram) return 1;
  74.     memset(HD63484_ram,0,0x200000);
  75.     return 0;
  76. }
  77.  
  78. void HD63484_stop(void)
  79. {
  80.     free(HD63484_ram);
  81.     HD63484_ram = 0;
  82. }
  83.  
  84. static void doclr(int opcode,UINT16 fill,int *dst,INT16 _ax,INT16 _ay)
  85. {
  86.     INT16 ax,ay;
  87.  
  88.     ax = _ax;
  89.     ay = _ay;
  90.  
  91.     for (;;)
  92.     {
  93.         for (;;)
  94.         {
  95.             switch (opcode & 0x0003)
  96.             {
  97.                 case 0:
  98.                     HD63484_ram[*dst]  = fill; break;
  99.                 case 1:
  100.                     HD63484_ram[*dst] |= fill; break;
  101.                 case 2:
  102.                     HD63484_ram[*dst] &= fill; break;
  103.                 case 3:
  104.                     HD63484_ram[*dst] ^= fill; break;
  105.             }
  106.             if (ax == 0) break;
  107.             else if (ax > 0)
  108.             {
  109.                 *dst = (*dst + 1) & 0x1fffff;
  110.                 ax--;
  111.             }
  112.             else
  113.             {
  114.                 *dst = (*dst - 1) & 0x1fffff;
  115.                 ax++;
  116.             }
  117.         }
  118.  
  119.         ax = _ax;
  120.         if (_ay < 0)
  121.         {
  122.             *dst = (*dst + 384 - ax) & 0x1fffff;
  123.             if (ay == 0) break;
  124.             ay++;
  125.         }
  126.         else
  127.         {
  128.             *dst = (*dst - 384 - ax) & 0x1fffff;
  129.             if (ay == 0) break;
  130.             ay--;
  131.         }
  132.     }
  133. }
  134.  
  135. static void docpy(int opcode,int src,int *dst,INT16 _ax,INT16 _ay)
  136. {
  137.     int dstep1,dstep2;
  138.     int ax = _ax;
  139.     int ay = _ay;
  140.  
  141.     switch (opcode & 0x0700)
  142.     {
  143.         default:
  144.         case 0x0000: dstep1 =  1; dstep2 = -384; break;
  145.         case 0x0100: dstep1 =  1; dstep2 =  384; break;
  146.         case 0x0200: dstep1 = -1; dstep2 = -384; break;
  147.         case 0x0300: dstep1 = -1; dstep2 =  384; break;
  148.         case 0x0400: dstep1 = -384; dstep2 =  1; break;
  149.         case 0x0500: dstep1 =  384; dstep2 =  1; break;
  150.         case 0x0600: dstep1 = -384; dstep2 = -1; break;
  151.         case 0x0700: dstep1 =  384; dstep2 = -1; break;
  152.     }
  153.     dstep2 -= ax * dstep1;
  154.  
  155.     for (;;)
  156.     {
  157.         for (;;)
  158.         {
  159.             switch (opcode & 0x0007)
  160.             {
  161.                 case 0:
  162.                     HD63484_ram[*dst]  = HD63484_ram[src]; break;
  163.                 case 1:
  164.                     HD63484_ram[*dst] |= HD63484_ram[src]; break;
  165.                 case 2:
  166.                     HD63484_ram[*dst] &= HD63484_ram[src]; break;
  167.                 case 3:
  168.                     HD63484_ram[*dst] ^= HD63484_ram[src]; break;
  169.                 case 4:
  170.                     if (HD63484_ram[*dst] == (ccmp & 0xff))
  171.                         HD63484_ram[*dst] = HD63484_ram[src];
  172.                     break;
  173.                 case 5:
  174.                     if (HD63484_ram[*dst] != (ccmp & 0xff))
  175.                         HD63484_ram[*dst] = HD63484_ram[src];
  176.                     break;
  177.                 case 6:
  178.                     if (HD63484_ram[*dst] < HD63484_ram[src])
  179.                         HD63484_ram[*dst] = HD63484_ram[src];
  180.                     break;
  181.                 case 7:
  182.                     if (HD63484_ram[*dst] > HD63484_ram[src])
  183.                         HD63484_ram[*dst] = HD63484_ram[src];
  184.                     break;
  185.             }
  186.  
  187.             if (opcode & 0x0800)
  188.             {
  189.                 if (ay == 0) break;
  190.                 else if (ay > 0)
  191.                 {
  192.                     src = (src - 384) & 0x1fffff;
  193.                     *dst = (*dst + dstep1) & 0x1fffff;
  194.                     ay--;
  195.                 }
  196.                 else
  197.                 {
  198.                     src = (src + 384) & 0x1fffff;
  199.                     *dst = (*dst + dstep1) & 0x1fffff;
  200.                     ay++;
  201.                 }
  202.             }
  203.             else
  204.             {
  205.                 if (ax == 0) break;
  206.                 else if (ax > 0)
  207.                 {
  208.                     src = (src + 1) & 0x1fffff;
  209.                     *dst = (*dst + dstep1) & 0x1fffff;
  210.                     ax--;
  211.                 }
  212.                 else
  213.                 {
  214.                     src = (src - 1) & 0x1fffff;
  215.                     *dst = (*dst + dstep1) & 0x1fffff;
  216.                     ax++;
  217.                 }
  218.             }
  219.         }
  220.  
  221.         if (opcode & 0x0800)
  222.         {
  223.             ay = _ay;
  224.             if (_ax < 0)
  225.             {
  226.                 src = (src - 1 - ay) & 0x1fffff;
  227.                 *dst = (*dst + dstep2) & 0x1fffff;
  228.                 if (ax == 0) break;
  229.                 ax++;
  230.             }
  231.             else
  232.             {
  233.                 src = (src + 1 - ay) & 0x1fffff;
  234.                 *dst = (*dst + dstep2) & 0x1fffff;
  235.                 if (ax == 0) break;
  236.                 ax--;
  237.             }
  238.         }
  239.         else
  240.         {
  241.             ax = _ax;
  242.             if (_ay < 0)
  243.             {
  244.                 src = (src + 384 - ax) & 0x1fffff;
  245.                 *dst = (*dst + dstep2) & 0x1fffff;
  246.                 if (ay == 0) break;
  247.                 ay++;
  248.             }
  249.             else
  250.             {
  251.                 src = (src - 384 - ax) & 0x1fffff;
  252.                 *dst = (*dst + dstep2) & 0x1fffff;
  253.                 if (ay == 0) break;
  254.                 ay--;
  255.             }
  256.         }
  257.     }
  258. }
  259.  
  260.  
  261. void HD63484_command_w(UINT16 cmd)
  262. {
  263.     int len;
  264.  
  265.     fifo[fifo_counter++] = cmd;
  266.  
  267.     len = instruction_length[fifo[0]>>10];
  268.     if (len == -1)
  269.     {
  270.         if (fifo_counter < 2) return;
  271.         else len = fifo[1]+2;
  272.     }
  273.     else if (len == -2)
  274.     {
  275.         if (fifo_counter < 2) return;
  276.         else len = 2*fifo[1]+2;
  277.     }
  278.  
  279.     if (fifo_counter >= len)
  280.     {
  281.         int i;
  282.  
  283.         logerror("PC %05x: HD63484 command %s (%04x) ",cpu_get_pc(),instruction_name[fifo[0]>>10],fifo[0]);
  284.         for (i = 1;i < fifo_counter;i++)
  285.             logerror("%04x ",fifo[i]);
  286.         logerror("\n");
  287.  
  288.         if (fifo[0] == 0x0400)    /* ORG */
  289.             org = ((fifo[1] & 0x00ff) << 12) | ((fifo[2] & 0xfff0) >> 4);
  290.         else if (fifo[0] == 0x0800)
  291.             cl0 = fifo[1];
  292.         else if (fifo[0] == 0x0801)
  293.             cl1 = fifo[1];
  294.         else if (fifo[0] == 0x0802)
  295.             ccmp = fifo[1];
  296.         else if (fifo[0] == 0x080c)
  297.             rwp = (rwp & 0x00fff) | ((fifo[1] & 0x00ff) << 12);
  298.         else if (fifo[0] == 0x080d)
  299.             rwp = (rwp & 0xff000) | ((fifo[1] & 0xfff0) >> 4);
  300.         else if (fifo[0] == 0x4800)    /* WT */
  301.         {
  302.             HD63484_ram[2*rwp]   = fifo[1] & 0x00ff ;
  303.             HD63484_ram[2*rwp+1] = (fifo[1] & 0xff00) >> 8;
  304.             rwp = (rwp + 1) & 0xfffff;
  305.         }
  306.         else if (fifo[0] == 0x5800)    /* CLR */
  307.         {
  308. rwp *= 2;
  309.             doclr(fifo[0],fifo[1],&rwp,2*fifo[2]+1,fifo[3]);
  310. rwp /= 2;
  311.         }
  312.         else if ((fifo[0] & 0xfffc) == 0x5c00)    /* SCLR */
  313.         {
  314. rwp *= 2;
  315.             doclr(fifo[0],fifo[1],&rwp,2*fifo[2]+1,fifo[3]);
  316. rwp /= 2;
  317.         }
  318.         else if ((fifo[0] & 0xf0ff) == 0x6000)    /* CPY */
  319.         {
  320.             int src;
  321.  
  322.             src = ((fifo[1] & 0x00ff) << 12) | ((fifo[2] & 0xfff0) >> 4);
  323. rwp *= 2;
  324.             docpy(fifo[0],2*src,&rwp,2*fifo[3]+1,fifo[4]);
  325. rwp /= 2;
  326.         }
  327.         else if ((fifo[0] & 0xf0fc) == 0x7000)    /* SCPY */
  328.         {
  329.             int src;
  330.  
  331.             src = ((fifo[1] & 0x00ff) << 12) | ((fifo[2] & 0xfff0) >> 4);
  332. rwp *= 2;
  333.             docpy(fifo[0],2*src,&rwp,2*fifo[3]+1,fifo[4]);
  334. rwp /= 2;
  335.         }
  336.         else if (fifo[0] == 0x8000)    /* AMOVE */
  337.         {
  338.             cpx = fifo[1];
  339.             cpy = fifo[2];
  340.         }
  341. //        else if ((fifo[0] & 0xff00) == 0xc000)    /* AFRCT */
  342.         else if ((fifo[0] & 0xfff8) == 0xc000)    /* AFRCT */
  343.         {
  344.             INT16 pcx,pcy;
  345.             INT16 ax,ay;
  346.             int dst;
  347.  
  348.             pcx = fifo[1];
  349.             pcy = fifo[2];
  350.             ax = pcx - cpx;
  351.             ay = pcy - cpy;
  352.             dst = (2*org + cpx - cpy * 384) & 0x1fffff;
  353.  
  354.             for (;;)
  355.             {
  356.                 for (;;)
  357.                 {
  358.                     switch (fifo[0] & 0x0007)
  359.                     {
  360.                         case 0:
  361.                             HD63484_ram[dst]  = cl0; break;
  362.                         case 1:
  363.                             HD63484_ram[dst] |= cl0; break;
  364.                         case 2:
  365.                             HD63484_ram[dst] &= cl0; break;
  366.                         case 3:
  367.                             HD63484_ram[dst] ^= cl0; break;
  368.                         case 4:
  369.                             if (HD63484_ram[dst] == (ccmp & 0xff))
  370.                                 HD63484_ram[dst] = cl0;
  371.                             break;
  372.                         case 5:
  373.                             if (HD63484_ram[dst] != (ccmp & 0xff))
  374.                                 HD63484_ram[dst] = cl0;
  375.                             break;
  376.                         case 6:
  377.                             if (HD63484_ram[dst] < (cl0 & 0xff))
  378.                                 HD63484_ram[dst] = cl0;
  379.                             break;
  380.                         case 7:
  381.                             if (HD63484_ram[dst] > (cl0 & 0xff))
  382.                                 HD63484_ram[dst] = cl0;
  383.                             break;
  384.                     }
  385.  
  386.                     if (ax == 0) break;
  387.                     else if (ax > 0)
  388.                     {
  389.                         dst = (dst + 1) & 0x1fffff;
  390.                         ax--;
  391.                     }
  392.                     else
  393.                     {
  394.                         dst = (dst - 1) & 0x1fffff;
  395.                         ax++;
  396.                     }
  397.                 }
  398.  
  399.                 ax = pcx - cpx;
  400.                 if (pcy < cpy)
  401.                 {
  402.                     dst = (dst + 384 - ax) & 0x1fffff;
  403.                     if (ay == 0) break;
  404.                     ay++;
  405.                 }
  406.                 else
  407.                 {
  408.                     dst = (dst - 384 - ax) & 0x1fffff;
  409.                     if (ay == 0) break;
  410.                     ay--;
  411.                 }
  412.             }
  413.         }
  414. //        else if ((fifo[0] & 0xf000) == 0xe000)    /* AGCPY */
  415.         else if ((fifo[0] & 0xf0f8) == 0xe000)    /* AGCPY */
  416.         {
  417.             INT16 pcx,pcy;
  418.             int src,dst;
  419.  
  420.             pcx = fifo[1];
  421.             pcy = fifo[2];
  422.             src = (2*org + pcx - pcy * 384) & 0x1fffff;
  423.             dst = (2*org + cpx - cpy * 384) & 0x1fffff;
  424.  
  425.             docpy(fifo[0],src,&dst,fifo[3],fifo[4]);
  426.  
  427.             cpx = (dst - 2*org) % 384;
  428.             cpy = (dst - 2*org) / 384;
  429.         }
  430.         else
  431. logerror("unsupported command\n");
  432.  
  433.         fifo_counter = 0;
  434.     }
  435. }
  436.  
  437. static int regno;
  438.  
  439. static READ_HANDLER( HD63484_status_r )
  440. {
  441.     if (offset == 1) return 0xff;    /* high 8 bits - not used */
  442.  
  443.     if (cpu_get_pc() != 0xfced6) logerror("%05x: HD63484 status read\n",cpu_get_pc());
  444.     return 0x22;    /* write FIFO ready + command end */
  445. }
  446.  
  447. static WRITE_HANDLER( HD63484_address_w )
  448. {
  449.     static unsigned char reg[2];
  450.  
  451.     reg[offset] = data;
  452.     regno = reg[0];    /* only low 8 bits are used */
  453. //if (offset == 0)
  454. //    logerror("PC %05x: HD63484 select register %02x\n",cpu_get_pc(),regno);
  455. }
  456.  
  457. static WRITE_HANDLER( HD63484_data_w )
  458. {
  459.     static unsigned char dat[2];
  460.  
  461.     dat[offset] = data;
  462.     if (offset == 1)
  463.     {
  464.         int val = dat[0] + 256 * dat[1];
  465.  
  466.         if (regno == 0)    /* FIFO */
  467.             HD63484_command_w(val);
  468.         else
  469.         {
  470. logerror("PC %05x: HD63484 register %02x write %04x\n",cpu_get_pc(),regno,val);
  471.             HD63484_reg[regno/2] = val;
  472.             if (regno & 0x80) regno += 2;    /* autoincrement */
  473.         }
  474.     }
  475. }
  476.  
  477. static READ_HANDLER( HD63484_data_r )
  478. {
  479.     int res;
  480.  
  481.     if (regno == 0x80)
  482.     {
  483.         res = cpu_getscanline();
  484.     }
  485.     else
  486.     {
  487. logerror("%05x: HD63484 read register %02x\n",cpu_get_pc(),regno);
  488.         res = 0;
  489.     }
  490.  
  491.     if (offset == 0)
  492.         return res & 0xff;
  493.     else
  494.         return (res >> 8) & 0xff;
  495. }
  496.  
  497.  
  498.  
  499.  
  500. void shanghai_vh_convert_color_prom(unsigned char *palette, unsigned short *colortable,const unsigned char *color_prom)
  501. {
  502.     int i;
  503.  
  504.  
  505.     for (i = 0;i < Machine->drv->total_colors;i++)
  506.     {
  507.         int bit0,bit1,bit2;
  508.  
  509.  
  510.         /* red component */
  511.         bit0 = (i >> 2) & 0x01;
  512.         bit1 = (i >> 3) & 0x01;
  513.         bit2 = (i >> 4) & 0x01;
  514.         *(palette++) = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
  515.         /* green component */
  516.         bit0 = (i >> 5) & 0x01;
  517.         bit1 = (i >> 6) & 0x01;
  518.         bit2 = (i >> 7) & 0x01;
  519.         *(palette++) = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
  520.         /* blue component */
  521.         bit0 = 0;
  522.         bit1 = (i >> 0) & 0x01;
  523.         bit2 = (i >> 1) & 0x01;
  524.         *(palette++) = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
  525.     }
  526. }
  527.  
  528. int shanghai_vh_start(void)
  529. {
  530.     return HD63484_start();
  531. }
  532.  
  533. void shanghai_vh_stop(void)
  534. {
  535.     HD63484_stop();
  536. }
  537.  
  538. void shanghai_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
  539. {
  540.     int x,y,b;
  541.     static int base,bose=256;
  542. if (keyboard_pressed_memory(KEYCODE_Z)) base -= 384/2*280;
  543. if (keyboard_pressed_memory(KEYCODE_X)) base += 384/2*280;
  544. if (keyboard_pressed_memory(KEYCODE_C)) bose--;
  545. if (keyboard_pressed_memory(KEYCODE_V)) bose++;
  546.  
  547.     b = 2 * (base + ((HD63484_reg[0xcc/2] & 0x001f) << 16) + HD63484_reg[0xce/2]);
  548.     for (y = 0;y < 280;y++)
  549.     {
  550.         for (x = 0;x < 384;x++)
  551.         {
  552.             b &= 0x1fffff;
  553.             plot_pixel(bitmap,x,y,Machine->pens[HD63484_ram[b]]);
  554.             b++;
  555.         }
  556.     }
  557.  
  558.     if ((HD63484_reg[0x06/2] & 0x0300) == 0x0300)
  559.     {
  560.         b = 2 * (base + ((HD63484_reg[0xdc/2] & 0x001f) << 16) + HD63484_reg[0xde/2]);
  561.         for (y = 0;y < 280;y++)
  562.         {
  563.             for (x = 0;x < 384;x++)
  564.             {
  565.                 b &= 0x1fffff;
  566.                 if (HD63484_ram[b])
  567.                     plot_pixel(bitmap,x,y,Machine->pens[HD63484_ram[b]]);
  568.                 b++;
  569.             }
  570.         }
  571.     }
  572. }
  573.  
  574.  
  575. static int shanghai_interrupt(void)
  576. {
  577.     interrupt_vector_w(0,0x80);
  578.     return interrupt();
  579. }
  580.  
  581. static WRITE_HANDLER( shanghai_coin_w )
  582. {
  583.     coin_counter_w(0,data & 1);
  584.     coin_counter_w(1,data & 2);
  585. }
  586.  
  587. static struct MemoryReadAddress readmem[] =
  588. {
  589.     { 0x00000, 0x03fff, MRA_RAM },
  590.     { 0xa0000, 0xfffff, MRA_ROM },
  591.     { -1 }    /* end of table */
  592. };
  593.  
  594. static struct MemoryWriteAddress writemem[] =
  595. {
  596.     { 0x00000, 0x03fff, MWA_RAM },
  597.     { 0xa0000, 0xfffff, MWA_ROM },
  598.     { -1 }    /* end of table */
  599. };
  600.  
  601. static struct IOReadPort readport[] =
  602. {
  603.     { 0x00, 0x01, HD63484_status_r },
  604.     { 0x02, 0x03, HD63484_data_r },
  605.     { 0x20, 0x20, YM2203_status_port_0_r },
  606.     { 0x22, 0x22, YM2203_read_port_0_r },
  607.     { 0x40, 0x40, input_port_0_r },
  608.     { 0x44, 0x44, input_port_1_r },
  609.     { 0x48, 0x48, input_port_2_r },
  610.     { -1 }  /* end of table */
  611. };
  612.  
  613. static struct IOWritePort writeport[] =
  614. {
  615.     { 0x00, 0x01, HD63484_address_w },
  616.     { 0x02, 0x03, HD63484_data_w },
  617.     { 0x20, 0x20, YM2203_control_port_0_w },
  618.     { 0x22, 0x22, YM2203_write_port_0_w },
  619.     { 0x4c, 0x4c, shanghai_coin_w },
  620.     { -1 }  /* end of table */
  621. };
  622.  
  623.  
  624.  
  625. INPUT_PORTS_START( shanghai )
  626.     PORT_START    /* IN0 */
  627.     PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_JOYSTICK_UP    | IPF_8WAY )
  628.     PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN  | IPF_8WAY )
  629.     PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT  | IPF_8WAY )
  630.     PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT | IPF_8WAY )
  631.     PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_BUTTON1 )
  632.     PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_BUTTON2 )
  633.     PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_BUTTON3 )
  634.     PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_UNKNOWN )
  635.  
  636.     PORT_START    /* IN1 */
  637.     PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_JOYSTICK_UP    | IPF_8WAY | IPF_COCKTAIL )
  638.     PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN  | IPF_8WAY | IPF_COCKTAIL )
  639.     PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT  | IPF_8WAY | IPF_COCKTAIL )
  640.     PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT | IPF_8WAY | IPF_COCKTAIL )
  641.     PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_BUTTON1 | IPF_COCKTAIL )
  642.     PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_BUTTON2 | IPF_COCKTAIL )
  643.     PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_BUTTON3 | IPF_COCKTAIL )
  644.     PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_UNKNOWN )
  645.  
  646.     PORT_START    /* IN2 */
  647.     PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_COIN1 )
  648.     PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_COIN2 )
  649.     PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_COIN3 )
  650.     PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_START1 )
  651.     PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_START2 )
  652.     PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_UNKNOWN )
  653.     PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_UNKNOWN )
  654.     PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_UNKNOWN )
  655.  
  656.     PORT_START    /* DSW0 */
  657.     PORT_SERVICE( 0x01, IP_ACTIVE_LOW )
  658.     PORT_DIPNAME( 0x02, 0x02, "Allow Continue" )
  659.     PORT_DIPSETTING(    0x00, DEF_STR( No ) )
  660.     PORT_DIPSETTING(    0x02, DEF_STR( Yes ) )
  661.     PORT_DIPNAME( 0x1c, 0x1c, DEF_STR( Coin_B ) )
  662.     PORT_DIPSETTING(    0x00, DEF_STR( 5C_1C ) )
  663.     PORT_DIPSETTING(    0x04, DEF_STR( 4C_1C ) )
  664.     PORT_DIPSETTING(    0x08, DEF_STR( 3C_1C ) )
  665.     PORT_DIPSETTING(    0x0c, DEF_STR( 2C_1C ) )
  666.     PORT_DIPSETTING(    0x1c, DEF_STR( 1C_1C ) )
  667.     PORT_DIPSETTING(    0x18, DEF_STR( 1C_2C ) )
  668.     PORT_DIPSETTING(    0x14, DEF_STR( 1C_3C ) )
  669.     PORT_DIPSETTING(    0x10, DEF_STR( 1C_4C ) )
  670.     PORT_DIPNAME( 0xe0, 0xe0, DEF_STR( Coin_A ) )
  671.     PORT_DIPSETTING(    0x00, DEF_STR( 5C_1C ) )
  672.     PORT_DIPSETTING(    0x20, DEF_STR( 4C_1C ) )
  673.     PORT_DIPSETTING(    0x40, DEF_STR( 3C_1C ) )
  674.     PORT_DIPSETTING(    0x60, DEF_STR( 2C_1C ) )
  675.     PORT_DIPSETTING(    0xe0, DEF_STR( 1C_1C ) )
  676.     PORT_DIPSETTING(    0xc0, DEF_STR( 1C_2C ) )
  677.     PORT_DIPSETTING(    0xa0, DEF_STR( 1C_3C ) )
  678.     PORT_DIPSETTING(    0x80, DEF_STR( 1C_4C ) )
  679.  
  680.     PORT_START    /* DSW1 */
  681.     PORT_DIPNAME( 0x01, 0x01, "Confirmation" )
  682.     PORT_DIPSETTING(    0x01, DEF_STR( No ) )
  683.     PORT_DIPSETTING(    0x00, DEF_STR( Yes ) )
  684.     PORT_DIPNAME( 0x02, 0x02, "Help" )
  685.     PORT_DIPSETTING(    0x00, DEF_STR( Off ) )
  686.     PORT_DIPSETTING(    0x02, DEF_STR( On ) )
  687.     PORT_DIPNAME( 0x0c, 0x0c, "2 Players Move Time" )
  688.     PORT_DIPSETTING(    0x0c, "8" )
  689.     PORT_DIPSETTING(    0x08, "10" )
  690.     PORT_DIPSETTING(    0x04, "12" )
  691.     PORT_DIPSETTING(    0x00, "14" )
  692.     PORT_DIPNAME( 0x30, 0x30, "Bonus Time for Making Pair" )
  693.     PORT_DIPSETTING(    0x30, "3" )
  694.     PORT_DIPSETTING(    0x20, "4" )
  695.     PORT_DIPSETTING(    0x10, "5" )
  696.     PORT_DIPSETTING(    0x00, "6" )
  697.     PORT_DIPNAME( 0xc0, 0xc0, "Start Time" )
  698.     PORT_DIPSETTING(    0xc0, "30" )
  699.     PORT_DIPSETTING(    0x80, "60" )
  700.     PORT_DIPSETTING(    0x40, "90" )
  701.     PORT_DIPSETTING(    0x00, "120" )
  702. INPUT_PORTS_END
  703.  
  704.  
  705.  
  706. static struct YM2203interface ym2203_interface =
  707. {
  708.     1,            /* 1 chip */
  709.     1500000,    /* ??? */
  710.     { YM2203_VOL(80,15) },
  711.     { input_port_3_r },
  712.     { input_port_4_r },
  713.     { 0 },
  714.     { 0 }
  715. };
  716.  
  717.  
  718.  
  719. static struct MachineDriver machine_driver_shanghai =
  720. {
  721.     /* basic machine hardware */
  722.     {
  723.         {
  724.             CPU_V30,
  725.             16000000,    /* ??? */
  726.             readmem,writemem,readport,writeport,
  727.             shanghai_interrupt,1,
  728.             0,0
  729.         }
  730.     },
  731.     30, DEFAULT_60HZ_VBLANK_DURATION,    /* frames per second, vblank duration */
  732.     1,    /* single CPU, no need for interleaving */
  733.     0,
  734.  
  735.     /* video hardware */
  736.     384, 280, { 0, 384-1, 0, 280-1 },
  737.     0,
  738.     256,0,
  739.     shanghai_vh_convert_color_prom,
  740.  
  741.     VIDEO_TYPE_RASTER,
  742.     0,
  743.     shanghai_vh_start,
  744.     shanghai_vh_stop,
  745.     shanghai_vh_screenrefresh,
  746.  
  747.     /* sound hardware */
  748.     0,0,0,0,
  749.     {
  750.         {
  751.             SOUND_YM2203,
  752.             &ym2203_interface
  753.         }
  754.     }
  755. };
  756.  
  757.  
  758.  
  759. /***************************************************************************
  760.  
  761.   Game driver(s)
  762.  
  763. ***************************************************************************/
  764.  
  765. ROM_START( shanghai )
  766.     ROM_REGION( 0x100000, REGION_CPU1 )
  767.     ROM_LOAD_V20_EVEN( "shg-22a.rom", 0xa0000, 0x10000, 0xe0a085be )
  768.     ROM_LOAD_V20_ODD ( "shg-21a.rom", 0xa0000, 0x10000, 0x4ab06d32 )
  769.     ROM_LOAD_V20_EVEN( "shg-28a.rom", 0xc0000, 0x10000, 0x983ec112 )
  770.     ROM_LOAD_V20_ODD ( "shg-27a.rom", 0xc0000, 0x10000, 0x41af0945 )
  771.     ROM_LOAD_V20_EVEN( "shg-37b.rom", 0xe0000, 0x10000, 0x3f192da0 )
  772.     ROM_LOAD_V20_ODD ( "shg-36b.rom", 0xe0000, 0x10000, 0xa1d6af96 )
  773. ROM_END
  774.  
  775.  
  776.  
  777. GAMEX( 1988, shanghai, 0, shanghai, shanghai, 0, ROT0, "Sun Electronics (licensed from Activision)", "Shanghai", GAME_NOT_WORKING )
  778.